package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.Server;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.SQLUtil;
import com.lineage.server.utils.log.PlayerLogUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;

public class resolvent11 {
  private static ArrayList<ArrayList<Object>> aData17 = new ArrayList();
  
  private static boolean NO_MORE_GET_DATA17 = false;
  
  private static Random _random = new Random();
  
  public static final String TOKEN = ",";
  
  public static void main(String[] a) {
    try {
      while (true)
        Server.main(null); 
    } catch (Exception exception) {
      return;
    } 
  }
  
  public static void forresolvent(L1PcInstance pc, L1ItemInstance item, int l) {
    int itemid = item.getItemId();
    L1ItemInstance tgitem = pc.getInventory().getItem(l);
    ArrayList aTempData = null;
    int[] iTemp = null;
    if (!NO_MORE_GET_DATA17) {
      NO_MORE_GET_DATA17 = true;
      getData17();
    } 
    int i = 0;
    while (i < aData17.size()) {
      aTempData = aData17.get(i);
      if (((Integer)aTempData.get(0)).intValue() == itemid && (
        (Integer)aTempData.get(0)).intValue() == item.getItemId() && (
        (Integer)aTempData.get(5)).intValue() == tgitem.getItemId()) {
        if (tgitem.getBless() >= 4) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("该装备受到封印卷轴的影响。"));
          return;
        } 
        if (tgitem.isEquipped()) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("请先把装备脱掉在使用。"));
          return;
        } 
        if (pc.getInventory().getSize() >= 170) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("身上物品太多无法进行升级"));
          return;
        } 
        if (pc.getInventory().getWeight() / pc.getMaxWeight() * 100.0D > 90.0D) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("身上负重限制无法进行升级"));
          return;
        } 
        if (pc.getDoll(tgitem.getId()) != null) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(1181));
          return;
        } 
        if (((Integer)aTempData.get(6)).intValue() >= _random.nextInt(100) + 1) {
          int MinCount = ((Integer)aTempData.get(8)).intValue();
          int MaxCount = ((Integer)aTempData.get(9)).intValue();
          int AddCount = MaxCount - MinCount + 1;
          L1ItemInstance Item3 = ItemTable.get()
            .createItem(((Integer)aTempData.get(7)).intValue());
          if (AddCount > 1)
            MinCount += _random.nextInt(AddCount); 
          if (MinCount > 0) {
            pc.getInventory().storeItem(((Integer)aTempData.get(7)).intValue(), 
                Integer.valueOf(MinCount).intValue());
            pc.sendPackets((ServerBasePacket)new S_SystemMessage((String)aTempData.get(10)));
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("获得" + Item3.getLogName() + " 数量: " + MinCount));
          } else {
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(1161));
          } 
        } else {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage((String)aTempData.get(11)));
        } 
        pc.getInventory().removeItem(tgitem.getId(), 1L);
        L1ItemInstance item2 = pc.getInventory().findItemId(((Integer)aTempData.get(0)).intValue());
        pc.getInventory().removeItem(item2.getId(), 1L);
      } 
      i++;
    } 
  }
  
  private static void getData17() {
    Connection con = null;
    try {
      con = DatabaseFactory.get().getConnection();
      Statement stat = con.createStatement();
      ResultSet rset = stat.executeQuery("SELECT * FROM w_物品分解系统");
      ArrayList aReturn = null;
      String sTemp = null;
      if (rset != null)
        while (rset.next()) {
          aReturn = new ArrayList();
          aReturn.add(0, new Integer(rset.getInt("道具编号")));
          aReturn.add(1, Integer.valueOf(0));
          aReturn.add(2, Integer.valueOf(0));
          aReturn.add(3, Integer.valueOf(0));
          aReturn.add(4, Integer.valueOf(0));
          aReturn.add(5, new Integer(rset.getInt("被分解物品")));
          aReturn.add(6, new Integer(rset.getInt("机率")));
          aReturn.add(7, new Integer(rset.getInt("获得物品")));
          aReturn.add(8, new Integer(rset.getInt("获得最小数量")));
          aReturn.add(9, new Integer(rset.getInt("获得最大数量")));
          aReturn.add(10, rset.getString("分解成功讯息"));
          aReturn.add(11, rset.getString("分解失败讯息"));
          aReturn.add(12, Integer.valueOf(0));
          aData17.add(aReturn);
        }  
      SQLUtil.close(rset);
      SQLUtil.close(stat);
      SQLUtil.close(con);
    } catch (Exception exception) {}
  }
  
  public static void 升级成功(String info) {
    PlayerLogUtil.writeLog("[升级成功]", info);
  }
  
  private static Object getArray(String s, String sToken, int iType) {
    StringTokenizer st = new StringTokenizer(s, sToken);
    int iSize = st.countTokens();
    String sTemp = null;
    if (iType == 1) {
      int[] iReturn = new int[iSize];
      int i = 0;
      while (i < iSize) {
        sTemp = st.nextToken();
        iReturn[i] = Integer.parseInt(sTemp);
        i++;
      } 
      return iReturn;
    } 
    if (iType == 2) {
      String[] sReturn = new String[iSize];
      int i = 0;
      while (i < iSize) {
        sTemp = st.nextToken();
        sReturn[i] = sTemp;
        i++;
      } 
      return sReturn;
    } 
    if (iType == 3) {
      String sReturn2 = null;
      int i = 0;
      while (i < iSize) {
        sTemp = sReturn2 = st.nextToken();
        i++;
      } 
      return sReturn2;
    } 
    return null;
  }
}
